<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<RMH.Entities.Room>>" %>
<%@ Import Namespace="RMH.Entities"%>

<script runat="server">private string RoomStatus(Room room)
    {
    var stay =
        room.Stays.FirstOrDefault(
            s => s.CheckinDate < DateTime.Now && (s.CheckoutDate == null || s.CheckoutDate > DateTime.Now));
    if (stay == null)
    {
        return string.Empty;
    }
    return stay.Type.ToString();
    }
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Index
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Index</h2>

    <table>
        <tr>
            <th></th>
            <th>
                RoomNumber
            </th>
            <th>
				Current Status
            </th>
        </tr>

    <% foreach (var item in Model) { %>
    
        <tr>
            <td>
                <%= Html.ActionLink("Details", "Details", new { id = item.Id })%>
            </td>
            <td>
                <%= Html.Encode(item.RoomNumber) %>
            </td>
            <td>
              <%= Html.Encode(RoomStatus(item)) %>
            </td>
        </tr>
    
    <% } %>

    </table>

    <p>
        <%= Html.ActionLink("Create New", "Edit") %>
    </p>

</asp:Content>

